using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Text;

namespace BetterEventViewer.Core
{
    public class BetterEventLogStore
    {
        public Collection<BetterEventLog> BetterEventLogs
        {
            get 
            {
                Collection<BetterEventLog> list = new Collection<BetterEventLog>();

                foreach( EventLog eventLog in EventLog.GetEventLogs() )
                {
                    BetterEventLog log = new BetterEventLog();
                    log.Component = eventLog;
                    list.Add(log);
                }

                return list;
            }
        }

        public BetterEventLog GetBetterEventLogByName(string name)
        {
            BetterEventLog result = new BetterEventLog();

            foreach (BetterEventLog log in BetterEventLogs)
            {
                if (log.Name == name)
                {
                    result = log;
                    break;
                }
            }

            return result;
        }

        public BetterEventLog CreateBetterEventLog(string name)
        {
            if (!EventLog.Exists(name))
            { 
                EventLog.CreateEventSource(name, name);
            }
            return GetBetterEventLogByName(name);
        }

        public void DeleteLogs()
        {
            foreach (BetterEventLog log in BetterEventLogs)
            {
                log.Delete();
            }
        }

        public void ClearAllEntries()
        {
            foreach (BetterEventLog log in BetterEventLogs)
            {
                log.ClearEntries();
            }
        }
    }
}
